import { buildApiUrl, reqDelete, reqGet, reqPost, reqPut } from '@render/util/AjaxUtil'
import FrontPageResult from '@render/util/FrontPageResult'
import { cloneDeep } from 'lodash-unified'

export async function add(bo: Project) {
  const url = buildApiUrl('/project/add')
  await reqPost(url, bo)
}

export async function modify(bo: Project) {
  const url = buildApiUrl('/project/modify')
  const ret = cloneDeep(bo)
  delete ret['createdAt']
  delete ret['updatedAt']
  delete ret['_X_ROW_KEY']
  await reqPut(url, ret)
}

export async function page(current: number, size: number) {
  const url = buildApiUrl('/project/page')
  return await reqGet<FrontPageResult<Project>>(url, { current, size })
}

export async function remove(ids: number[]) {
  const url = buildApiUrl('/project/remove')
  await reqDelete(url, { id: ids })
}
